import axios from 'axios'

const host = 'http://47.56.231.11:3001'
axios.interceptors.request.use(function(config) {
    const token = sessionStorage.getItem('token')
        // config是请求的配置对象,里面存储的有当前的请求方法、请求路径、请求头信息
    if (token) {
        // config.baseURL= host + '/',
        config.headers.Authorization = token
        config.headers['Content-Type'] = 'application/json'
    }
    return config
})


export function fetch_login(params) {
    return axios.post(host + '/api/login', params)
}

export function fetch_register(params) {
    return axios.post(host + '/api/userregister', params)
}

export function user_data(params) {
    return axios.get(host + '/api/viewinformation', params)
}


export function user_setting(params) {
    return axios.post(host + '/api/usersettings', params)
}


export function uploadImg(params) {
    return axios.post(host + '/api/file/upload', params)
}

export function changePwd(params) {
    return axios.post(host + `/api/changepassword?newpassword=${params}`)
}

export function Promotion(params) {
    return axios.post(host + '/api/group/updatememberidentity', params)
}

export function sendRedPacket(params) {
    return axios.post(host + '/api/redpacket/send', params)
}

export function grabRedPacket(params) {
    return axios.post(host + '/api/redpacket/open', params)
}

// export function checkUserMoney(params) {
//     return axios.post(host + `/api/redpacket/usermoney/${params}`)
// }

export function showRedPacketDetail(params) {
    return axios.get(host + `/api/redpacket/${params}`)
}

export function getAnnounce(params) {
  return axios.get(host + `/api/announcement?noticeId=${params}`)
}
